Repository navigation
Conversation
| PLZN_REPO="reneme/plzn" | ||
|
|
||
| # The git revision of plzn to use | ||
| PLZN_GIT_REV=6676a26b08458f8fe5dad96316cb4624c7d3ef34 | ||
| PLZN_GIT_REV=814920de917acca6bbc48073ffa8e851180d0ee0 |
There was a problem hiding this comment.
Note to self: Don't forget to switch that back to randombit/plnz once randombit/plzn#10 landed.
Not yet supported is the Connection ID (CID) and variable MTUs for retransmissions. Co-Authored-By: René Meusel <rene.meusel@rohde-schwarz.com>
f1476cd to
089b4a1
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects permit replay-window poisoning, AEAD nonce reuse, and deprotection-limit bypasses, and can cause handshake timeouts and post-close ACK failures.
9 open issues
Send ACKs in batches to cover large final flights · New Suppress ACKs after write-side closure · New Reject exhausted record counters before encryption · New Enforce deprotection failure limits for retained epochs · New Do not advance the replay window for unauthenticated records · New Reject zero handshake timeout settings · New Keep restricted policies from enabling DTLS 1.3 by default · New Avoid allocating reassembly buffers for duplicate fragments · New Limit handshake padding to the remaining datagram capacity · New
What changed in this PR
Adds experimental DTLS 1.3 support to Botan by connecting datagram-specific I/O to the existing TLS 1.3 state machine, completing #5000.
Changes:
- Implements DTLS records, fragmentation, acknowledgements, retransmissions, and flight timers.
- Integrates version negotiation, DTLS 1.2 downgrade handling, and policy settings.
- Updates conformance shims, CI configurations, tests, and documentation.
| File | Description |
|---|---|
src/tests/unit_tls.cpp |
Adds DTLS downgrade and version-mismatch cases. |
src/tests/test_tls_protocol_version.cpp |
Recognizes available DTLS 1.3 builds. |
src/tests/test_dtls12.cpp |
Keeps DTLS 1.2 tests version-specific. |
src/scripts/ci/gha_linux_packages.py |
Supplies dependencies for the new CI variant. |
src/scripts/ci_build.py |
Adds builds without DTLS 1.3. |
src/plzn_shim/plzn_shim.cpp |
Enables DTLS 1.3 conformance configuration. |
src/plzn_shim/expectations.json |
Excludes unsupported live-MTU testing. |
src/lib/tls/tls13/tls_types_13.h |
Adds fragment and serialized-record wrappers. |
src/lib/tls/tls13/tls_server_impl_13.cpp |
Initializes protocol-specific server I/O. |
src/lib/tls/tls13/tls_record_layer_13.cpp |
Uses the shared content-type length constant. |
src/lib/tls/tls13/tls_record_13.h |
Adds ACK records to the record variant. |
src/lib/tls/tls13/tls_record_13.cpp |
Dispatches ACK record content. |
src/lib/tls/tls13/tls_messages_13.h |
Includes HelloVerifyRequest downgrade messages. |
src/lib/tls/tls13/tls_handshake_state_13.h |
Declares HelloVerifyRequest state storage. |
src/lib/tls/tls13/tls_handshake_state_13.cpp |
Stores HelloVerifyRequest messages. |
src/lib/tls/tls13/tls_handshake_layer_13.cpp |
Adds HelloVerifyRequest boundary validation. |
src/lib/tls/tls13/tls_client_impl_13.h |
Declares the DTLS downgrade handler. |
src/lib/tls/tls13/tls_client_impl_13.cpp |
Initializes I/O and handles DTLS downgrades. |
src/lib/tls/tls13/tls_cipher_state.h |
Exposes authentication-failure counters. |
src/lib/tls/tls13/tls_cipher_state.cpp |
Selects DTLS cipher states and initializes counters. |
src/lib/tls/tls13/tls_channel_io.h |
Extends shared I/O interfaces for DTLS. |
src/lib/tls/tls13/tls_channel_io.cpp |
Routes ACKs and DTLS key-update triggers. |
src/lib/tls/tls13/tls_channel_impl_13.h |
Exposes shutdown and I/O initialization. |
src/lib/tls/tls13/tls_channel_impl_13.cpp |
Initializes I/O and adjusts plaintext-record handling. |
src/lib/tls/tls_version.cpp |
Recognizes DTLS 1.3 when available. |
src/lib/tls/tls_text_policy.cpp |
Parses new DTLS policy settings. |
src/lib/tls/tls_policy.h |
Declares DTLS timers and resource limits. |
src/lib/tls/tls_policy.cpp |
Implements DTLS defaults and flight-timeout calculation. |
src/lib/tls/tls_magic.h |
Adds ACK and shared timing/record constants. |
src/lib/tls/tls_extensions.cpp |
Offers DTLS 1.3 in supported versions. |
src/lib/tls/tls_client.cpp |
Allows DTLS 1.3 client creation. |
src/lib/tls/tls_channel.h |
Clarifies DTLS timer accessor documentation. |
src/lib/tls/tls_channel_impl.h |
Grants DTLS I/O channel-state access. |
src/lib/tls/msg_client_hello.cpp |
Uses flavor-specific legacy version selection. |
src/lib/tls/dtls13/tls_utils_dtls13.h |
Implements sequence reconstruction and replay windows. |
src/lib/tls/dtls13/tls_types_dtls13.h |
Defines DTLS-specific type wrappers. |
src/lib/tls/dtls13/tls_timer_dtls13.h |
Implements deferred retransmission and flight timers. |
src/lib/tls/dtls13/tls_record_layer_dtls13.h |
Declares DTLS record-layer state and operations. |
src/lib/tls/dtls13/tls_record_layer_dtls13.cpp |
Processes datagrams, retransmissions, and acknowledgements. |
src/lib/tls/dtls13/tls_record_dtls13.h |
Defines plaintext and protected record structures. |
src/lib/tls/dtls13/tls_record_dtls13.cpp |
Parses and serializes DTLS record headers. |
src/lib/tls/dtls13/tls_handshake_layer_dtls13.h |
Declares fragmentation and reassembly interfaces. |
src/lib/tls/dtls13/tls_handshake_layer_dtls13.cpp |
Fragments and reassembles handshake messages. |
src/lib/tls/dtls13/tls_cipher_state_dtls13.h |
Declares retained protection epochs. |
src/lib/tls/dtls13/tls_cipher_state_dtls13.cpp |
Protects records and masks sequence numbers. |
src/lib/tls/dtls13/tls_channel_io_dtls13.h |
Declares DTLS I/O coordination and timers. |
src/lib/tls/dtls13/tls_ack_record_dtls13.h |
Declares ACK payload operations. |
src/lib/tls/dtls13/tls_ack_record_dtls13.cpp |
Parses, serializes, and validates acknowledgements. |
src/lib/tls/dtls13/info.txt |
Registers the experimental DTLS 1.3 module. |
src/editors/vscode/scripts/bogo.py |
Adds DTLS-disabled conformance-run options. |
src/configs/repo_config.env |
Updates the plzn harness source and revision. |
src/bogo_shim/config.json |
Enables DTLS 1.3 conformance cases. |
src/bogo_shim/config_no_tls12.json |
Enables DTLS 1.3-only conformance coverage. |
src/bogo_shim/config_no_dtls13.json |
Adds expectations for DTLS-disabled builds. |
src/bogo_shim/bogo_shim.cpp |
Adds DTLS policies and test controls. |
readme.rst |
Advertises experimental DTLS 1.3 support. |
doc/credits.rst |
Credits DTLS 1.3 contributions. |
doc/api_ref/tls.rst |
Documents DTLS support, timers, and API constraints. |
.github/workflows/ci.yml |
Adds the DTLS-disabled CI matrix entry. |
Review effort: Max
| const auto max_ack_records = (max_plaintext_length - length_field_size) / record_number_size; | ||
| BOTAN_DEBUG_ASSERT(max_ack_records > 0); | ||
|
|
||
| const auto acks_to_serialize = std::min<size_t>(m_record_numbers.size(), max_ack_records); |
| send_data(Record_Type::ACK, m_record_layer.acknowledgements().serialize(max_plaintext_length), cipher_state().get()); | ||
| } |
| const auto marshalled_record = | ||
| marshall_and_protect(epoch, unified_header.serialize(), payload, type, padding_bytes, out); |
| if(cs != nullptr && cs->current_read_epoch_deprotection_failures() > m_deprotection_failure_limit) { | ||
| throw TLS_Exception(Alert::BadRecordMac, "Too many deprotection failures in current read epoch"); |
| // the lifetime of the association. This check SHOULD happen after | ||
| // deprotecting the record; otherwise, the record discard might | ||
| // itself serve as a timing channel for the record number. | ||
| auto& window = replay_window_for_epoch(record.epoch.value()); |
| .retransmission_timer = {}, | ||
| .flight_timer = {}, | ||
| })) { | ||
| BOTAN_ASSERT_NONNULL(m_token->callbacks); |
| #if defined(BOTAN_HAS_DTLS_13) | ||
| return true; |
| auto [itr, _] = | ||
| m_current_read_message.try_emplace(header.message_sequence_number, | ||
| ReassembledMessage{ | ||
| .message = | ||
| { | ||
| .epoch_number = data_from_peer.epoch, | ||
| .type = read_handshake_message_type(header.msg_type), | ||
| .header = header.serialize_tls_header_portion(), | ||
| .payload = SerializedHandshakeMessage(header.message_length), | ||
| }, | ||
| .received_bytes = bitvector(header.message_length), | ||
| .complete = false, | ||
| }); |
| const size_t padding_length = | ||
| (pt_size_with_type_tag < max_record_size) | ||
| ? std::min(policy.record_padding_bytes(pt_size_with_type_tag), max_record_size - pt_size_with_type_tag) | ||
| : 0; |
|
@reneme I should have some time to start reviewing this next week.
I think we should just flatly not support this in DTLS 1.3. This has been a continual nightmare in 1.2. I just checked and the only other implementation I can even find that supports this is mbedtls, and it does so only in a very limited form - if enabled, and the server sees a epoch-0 CH on an active session, it performs a new cookie exchange [if the server didn't set a cookie or doesn't pass an identity string to mbedtls, it instead just drops the CH]. If the cookie exchange passes, mbedtls immediately clears the session and returns a specific error, after which the application itself must re-initiate the handshake. I was actually surprised, thinking this mechanism is not what the 1.2 RFC specifies, but (https://www.rfc-editor.org/info/rfc6347/#section-4.2.8)
Something of this form might be easy enough to support vs trying to keep a parallel handshake state in sync. And actually might play well with an idea you suggested a while back that we don't actually negotiate at all within the same Alternative imo (and what I was about to suggest until I looked further at how mbedtls does it) would be to completely deprecate and drop epoch0 restart handling in 1.2 |


This introduces an implementation of DTLS 1.3 (RFC 9147) as an additional experimental module "dtls13". It is based on the various preparatory PRs listed in #5000 and slides into the abstractions introduced in them.
Essentially, the entire I/O layer is now abstract and provides two implementations for TLS and DTLS respectively. Most of this complexity is encapsulated in the
Channel_IOclass and itsTLS_Channel_IO/DTLS_Channel_IOchildren which orchestrate flavor-specific sub-classes ofRecord_Layer,Handshake_Layer, andCipher_State. The TLS state machine essentially stays the same for both TLS and DTLS with some minor conditional additions in case of DTLS.Both BoGo (with a few exclusions) as well as plzn integration tests pass. First rounds of AI review didn't find any smoking guns. But of course, we're eager to see what Anthropic's OSS scanners come up with.
While we did have performance in mind for all parts of the implementation, this PR aims at a functionally correct protocol implementation first-and-foremost. Future improvements both on performance as well as resilience are obviously welcome, but given that this is meant to be an experimental module, we'd suggest to apply them iteratively as follow-ups.
New Components
Overview of added DTLS-specific components
DTLS_Channel_IODTLS_Record_LayerDTLS_Handshake_LayerDTLS_Cipher_StateSingleshotTimerTLS::Channel::tls_register_deferred_operation()RetransmissionTimerSingleshotTimersKnown Limitations and Open Issues
Deliberate omissions as well as potential future work
Downgrade transcript can pile up junk
The way the (D)TLS downgrade is implemented we currently pile up the entire incoming data transcript. When the state machine eventually detects a 1.3 to 1.2 downgrade, the internal implementation is exchanged and the entire received transcript is replayed for the then-active DTLS 1.2 implementation. Also the physical datagram boundaries are lost in the transcript stash, so truncated or deliberately invalid datagrams may corrupt the replay for the downgraded 1.2 implementation. This allows an attacker to pile up megabytes of junk. We'll have to make this more robust and perhaps cover this with some plzn regression tests.
DTLS 1.3 currently hard-requires TLS 1.3
The "dtls13" module depends on the "tls13" module, so DTLS 1.3 cannot be enabled without also enabling "tls13" at the moment. This could be addressed in the future, by introducing an internal "tls13_common" module that carries only the state machine implementation and abstract I/O layer components.
No support for Connection IDs (RFC 9146, RFC 9147 Section 9)
Connection IDs are transported in plaintext as part of the unified header of protected DTLS records and allow peers to map incoming datagrams with their appropriate security associations. This is helpful for applications that want to migrate existing DTLS sessions across different network transports.
Currently, Botan won't negotiate this extension and is thus compatible with implementations that support CIDs as long as their configuration profiles don't hard-require them.
Epoch0-Restart is not supported
If a peer sends a fresh ClientHello (epoch=0) into an existing association, it is simply ignored. No effort is taken to perform a new handshake that, once successful, replaces the existing association. In contrast, DTLS 1.2 does that. Note: an application can work around this limitation by actively detecting incoming ClientHello datagrams and launching their own shadow
TLS::Serverinstance.At this point it is unclear if and when this would ever be supported in DTLS 1.3. We could, however, implement a new
TLS::Callbackshook that notifies of an incoming ClientHello.Unprotected ACKs can abort a handshake early-on
RFC 9147 7.2 Errata 8108 says:
For consistency with BoringSSL (and to pass the relevant BoGo tests), we currently implemented the validation verbatim. However, that means that an off-path attacker could kill an upcoming handshake by sending such a malicious unauthenticated ACK record.
The vulnerable window is small, because we blanket-reject all plaintext ACK records as soon as we successfully deprotected any protected record from the peer (which BoringSSL does as well).
There is a recent, ongoing discussion about it in in the TLS-WG:
We plan to revisit this once the spec issue is resolved.
The deprecated
TLS::Channel::timeout_check()is not supportedWhen an existing application that uses
timeout_check()to steer DTLS retransmissions upgrades to a Botan version that default-enables DTLS 1.3, it might surprisingly experienceNot_Implementedexceptions from invoking this function.timeout_check()was deprecated recently for removal in Botan4, but still worth to be aware of. We don't plan to support thetimeout_check()method for DTLS 1.3.Re-fragmentation of messages after an MTU-change
The implementation can handle incoming retransmissions that were re-fragmented (eg. data offset overlaps with previous fragment), but it is currently not able to re-fragment and re-pack handshake datagrams after the MTU value reported by
TLS::Policy::dtls_default_mtu()got reduced.Future addition of this feature could benefit applications that require PQ keys and/or large certificate chains and thus have to rely on message fragmentation. If the MTU isn't known a-priori such applications will have to rely on a conservative guess of the MTU and thus loose throughput due to inefficient packing of datagrams.
While we believe that sophisticated MTU-discovery mechanisms should be out-of-scope for the library, a future improvement should provide enough flexibility so that an application can implement them efficiently for their specific use case.
Handshake message reassembly allocates upfront
We should look into abstracting the work done in #5803 and see if we can reuse it for DTLS 1.3 as well. The current implementation here works functionally but is vulnerable to large message pre-allocation.
Handling of pending KeyUpdates is currently sub-par
As discussed here, a pending KeyUpdate currently blocks all other user-solicited post-handshake messages (e.g.
TLS::Server::send_new_session_tickets()) via anInvalid_Stateexception. Additionally, the ACKnowledgement of pending KeyUpdates is currently not handled vianotify_received_complete_flight(). Instead, there's an ad-hoc handling tailored to just recognize the KeyUpdate's ACK and then act on it (i.e. advance the write epoch).For now this is fine, but we should refactor that so that future (more complicated) post-handshake mechanisms such as post-handshake client auth, Connection ID updates or the ExtendedKeyUpdate can be implemented based on a reusable scheme.
Retransmission triggers reflect BoringSSL deficiencies
RFC 9147 7.2 requests us to retransmit on receiving a partial ACK. Additionally, if we receive a retransmission of an already-seen flight without any of our messages being acknowledged, RFC 9147 5.8.1 asks us to retransmit the previous flight (see numbered list, specifically point 3).
Both of these conditions are not yet implemented. Instead, retransmissions are currently entirely timer-based. This (unintentionally) reflects BoringSSL's behavior crbug.com/383016430, which is why we decided to leave this as future work.
Closes #5000.